package cn.cheegon.blog.controller;

import cn.cheegon.blog.common.api.CommonResult;
import cn.cheegon.blog.entity.req.CommentAddReq;
import cn.cheegon.blog.model.CmsComment;
import cn.cheegon.blog.model.UmsAdmin;
import cn.cheegon.blog.service.CmsCommentService;
import cn.cheegon.blog.service.UmsAdminService;
import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Desc:
 * @Author: cheegon
 * @Date: Create in 2024/7/4  上午10:33
 */
@RestController
@RequestMapping("/consumer/*")
public class ConsumerController {
    @Autowired
    private CmsCommentService cmsCommentService;

    @Autowired
    private UmsAdminService umsAdminService;

    @PostMapping("comment/add")
    public CommonResult addComment(@RequestBody CommentAddReq req) {
        UmsAdmin currUser = umsAdminService.getCurrUser();
        CmsComment bean = BeanUtil.toBean(req, CmsComment.class);
        bean.setUid(currUser.getId());
        cmsCommentService.add(bean);
        return CommonResult.success();
    }
    @GetMapping("comment/del/{id}")
    public CommonResult del(@PathVariable Long id) {
        cmsCommentService.del(id);
        return CommonResult.success();
    }
}
